$def with (loans, action, pagecount=None, pageindex=None, stats=None)

$ pdf_count = len([pdf for pdf in loans if pdf['resource_type'] == 'pdf'])
$ epub_count = len([epub for epub in loans if epub['resource_type'] == 'epub'])
$ bookreader_count = len([bookreader for bookreader in loans if bookreader['resource_type'] == 'bookreader'])
$ total = pdf_count + epub_count + bookreader_count + 0.0
$ pdf_percent = "%d" % percentage(pdf_count, total)
$ epub_percent = "%d" % percentage(epub_count, total)
$ bookreader_percent = "%d" % percentage(bookreader_count, total)

<div id="contentHead">
    $:render_template("admin/menu")
    <h1>Outstanding eBook Loans</h1>
    <p id="note">
        <em class="red">Note:</em> ACS4 loan status for ePub and PDF is updated hourly and also on demand (when a user looks at a borrow page or their own loans).  You can refresh the status of a loan (synchronize with ACS4 server) by clicking on "refresh". BookReader loan status is always current.
    </p>
    <p>
        $# could do user checking here
        $if True:
            <form method="post" id="adminAction" name="adminAction" class="olform">
                <input type="hidden" name="action" value="updateall" />
                <input type="submit" value="Update ACS4 loan statuses" />
            </form>
        $else:
            <span class="adminOnly" style="font-size: 24px; line-height: 1.5em;"><i>THIS PAGE ISN'T UPDATING LIVE.</u><br />We're currently collecting stats - bulk status update is disabled.  <br />Please do not refresh loan status manually, thanks.</span>
    </p>
</div>
<div id="contentBody">
    $if pagecount is not None:
        <div style="margin-bottom: 30px; margin-top: -30px;">
            $:render_template("lib/pagination", pagecount, pageindex, "/admin/loans?page=%(page)s")
            <br style="clear: both;">
        </div>

    $:render_template("admin/loans_table", loans, show_percent=True, stats=stats)
    $if pagecount is not None:
        <div>
            $:render_template("lib/pagination", pagecount, pageindex, "/admin/loans?page=%(page)s")
        </div>
</div>
